/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.hibernate.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "AD_ORDER")
public class AdOrder extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//date formats
	public static final String FORMAT_START_TIME = DATE_FORMAT;
	public static final String FORMAT_END_TIME = DATE_FORMAT;
	public static final String FORMAT_CREATION_TIME = DATE_FORMAT;
	public static final String FORMAT_FIRST_START_TIME = DATE_FORMAT;
	public static final String FORMAT_LAST_END_TIME = DATE_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	
	private Long id;
	@NotNull 
	private Long adOwnerId;
	@NotBlank @Length(max=100)
	private String name;
	
	/**
	 * 1.投放
	 * 2.停止
	 */
	@NotBlank @Length(max=1)
	private String status;

	private String isShow;
	@NotNull 
	private java.util.Date creationTime;
	@Length(max=255)
	private String otherCode;
	@Length(max=500)
	private String remark;
	
	private Long totalprice;
	
	private Long price;
	
	private String otherOrderId;
	
	//每日消费上限 add by ZhangGuodong
	private Double dayPrice;
	
	//columns END


	public AdOrder(){
	}

	public AdOrder(
		Long id
	){
		this.id = id;
	}

	

	public void setId(Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "AD_OWNER_ID", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getAdOwnerId() {
		return this.adOwnerId;
	}
	
	public void setAdOwnerId(Long value) {
		this.adOwnerId = value;
	}
	
	@Column(name = "NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public String getName() {
		return this.name;
	}
	
	public void setName(String value) {
		this.name = value;
	}
	
	@Column(name = "STATUS", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public String getStatus() {
		return this.status;
	}
	
	public void setStatus(String value) {
		this.status = value;
	}
	
	@Column(name = "IS_SHOW")
	public String getIsShow() {
		return this.isShow;
	}
	
	public void setIsShow(String value) {
		this.isShow = value;
	}
	
	@Transient
	public String getCreationTimeString() {
		return DateConvertUtils.format(getCreationTime(), FORMAT_CREATION_TIME);
	}
	public void setCreationTimeString(String value) {
		setCreationTime(DateConvertUtils.parse(value, FORMAT_CREATION_TIME,java.util.Date.class));
	}
	
	@Column(name = "OTHER_ORDER_ID", unique = true, nullable = true, insertable = true, updatable = true, length = 50)
	public String getOtherOrderId() {
		return otherOrderId;
	}

	public void setOtherOrderId(String otherOrderId) {
		this.otherOrderId = otherOrderId;
	}

	@Column(name = "CREATION_TIME", unique = false, insertable = true, length = 7)
	public java.util.Date getCreationTime() {
		return this.creationTime;
	}
	
	public void setCreationTime(java.util.Date value) {
		this.creationTime = value;
	}

	
	@Column(name = "OTHER_CODE", unique = false, nullable = true, insertable = true, updatable = true, length = 255)
	public String getOtherCode() {
		return this.otherCode;
	}
	
	public void setOtherCode(String value) {
		this.otherCode = value;
	}
	
	@Column(name = "REMARK", unique = false, nullable = true, insertable = true, updatable = true, length = 500)
	public String getRemark() {
		return this.remark;
	}
	
	public void setRemark(String value) {
		this.remark = value;
	}
	
	@Column(name = "TOTALPRICE")
	public Long getTotalprice() {
		return this.totalprice;
	}
	
	public void setTotalprice(Long value) {
		this.totalprice = value;
	}

	@Column(name = "PRICE")
	public Long getPrice() {
		return this.price;
	}
	
	public void setPrice(Long value) {
		this.price = value;
	}
	
	/**
	 * add by ZhangGuodong start
	 * 每日消费上限
	 */
	public void setDayPrice(Double dayPrice) {
		this.dayPrice = dayPrice;
	}

	@Column(name = "DAY_PRICE", unique = false, nullable = true, insertable = true, updatable = true)
	public Double getDayPrice() {
		return dayPrice;
	}
	/**
	 * add by ZhangGuodong end
	 */
	
	/**
	 * delete by zgd
	 * date: 2011-12-08
	 */
//	private Set reports = new HashSet(0);
//	public void setReports(Set<Report> report){
//		this.reports = report;
//	}
//	
//	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.Lazy, mappedBy = "adOrder")
//	public Set<Report> getReports() {
//		return reports;
//	}
	
	private Set adPlans = new HashSet(0);
	public void setAdPlans(Set<AdPlan> adPlan){
		this.adPlans = adPlan;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "adOrder")
	@OrderBy("name")
	public Set<AdPlan> getAdPlans() {
		return adPlans;
	}
	
	private AdOwner adOwner;
	public void setAdOwner(AdOwner adOwner){
		this.adOwner = adOwner;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "AD_OWNER_ID",nullable = false, insertable = false, updatable = false) 
	})
	public AdOwner getAdOwner() {
		return adOwner;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("AdOwnerId",getAdOwnerId())
			.append("Name",getName())
			.append("Status",getStatus())
			.append("IsShow",getIsShow())
			.append("CreationTime",getCreationTime())
			.append("OtherCode",getOtherCode())
			.append("Remark",getRemark())
			.append("Totalprice",getTotalprice())
			.append("DayPrice", getDayPrice())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof AdOrder == false) return false;
		if(this == obj) return true;
		AdOrder other = (AdOrder)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "订单";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return getName();
	}

	
}

